package com.sc.nft.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.Version;
import com.sc.nft.enums.EcologyPoolLinkTypeEnum;
import com.sc.nft.enums.EcologyPoolTypeEnum;
import com.sc.nft.sup.SuperEntity;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Objects;

/**
 * @author 刘国航
 * @since 2024/7/15
 */
@Data
@NoArgsConstructor
@Accessors(chain = true)
@TableName("sc_ecology_pool")
public class EcologyPool extends SuperEntity implements Serializable {

    private static final long serialVersionUID = 5311453200541990437L;
    /**
     * 数量
     */
    private BigDecimal linkCount;

    /**
     * 物质类型
     */
    private EcologyPoolLinkTypeEnum linkType;

    /**
     * 品牌id
     */
    private Long daoId;

    /**
     * 用户id
     */
    private Long userId;

    /**
     * 生态池类型
     */
    private EcologyPoolTypeEnum poolType;

    /**
     * 唯一约束
     */
    private String pkCode;

    /**
     * 生态池名称
     */
    private String poolName;

    /**
     * 版本号
     */
    @Version
    private Integer version;

    /**
     * 组装唯一约束
     */
    public void buildPkCode() {
        this.pkCode = (Objects.nonNull(this.poolType) ? this.poolType.getCode() : "*") + "_"
                + (Objects.nonNull(this.linkType) ? this.linkType.getCode() : "*") + "_"
                + ((Objects.nonNull(this.daoId) && this.daoId > 0) ? this.daoId : "*") + "_"
                + ((Objects.nonNull(this.userId) && this.userId > 0) ? this.userId : "*");
    }

}
